import {mysqlInterface, databaseSessionKey} from "@/util/common";

export const saveDatabase = (database: mysqlInterface) => {
    const databaseListJson = localStorage.getItem(databaseSessionKey)
    let databaseList: mysqlInterface[] = []
    if (databaseListJson != null) {
        databaseList = JSON.parse(databaseListJson)
    }
    let isExists = false
    databaseList.map((db, index) => {
        if (`${db.host}/${db.database}` === `${database.host}/${db.database}`) {
            databaseList[index] = database
            isExists = true
        }
    })
    if (!isExists) {
        databaseList.push(database)
    }
    localStorage.setItem(databaseSessionKey, JSON.stringify(databaseList))
}
